package com.itboye.core.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;

public class TimesUtils {

	public TimesUtils() {
		/**
		 * 实例化失败
		 */
		throw new UnsupportedOperationException("cannot be instantiated");
	}

	/**
	 * 获取当前时间戳
	 * 
	 * @return int 类型数据
	 */
	public static String getStamp() {
		Long tsLong = System.currentTimeMillis() / 1000;
		String ts = tsLong.toString();
		return ts;
	}

	/**
	 * 计算SP的时间戳与当前时间戳的差
	 * 
	 * @param oldTime
	 *            旧的时间戳
	 * @return 时间差
	 */
	public static int getStampDiff(String oldTime) {
		Long tsLong = System.currentTimeMillis() / 1000;
		Long diffLong = tsLong - Long.parseLong(oldTime);
		int diffTime = Integer.parseInt(diffLong.toString());
		return diffTime;
	}

	/**
	 * Long.parseLong(timeStamp)
	 * 
	 * @param timeStamp
	 *            1451750400
	 * @return 2016
	 */
	public static int getYearByTimeStamp(long timeStamp) {
		String year = timeStamp2Date(timeStamp);
		return Integer.parseInt(year);
	}

	/**
	 * Long.parseLong(timeStamp)
	 * 
	 * @param timeStamp
	 *            1451750400
	 * @return 01
	 */
	public static int getMonthByTimeStamp(long timeStamp) {
		String date = timeStamp2Date(timeStamp);
		String month = date.substring(5, 7);
		return Integer.parseInt(month);
	}

	/**
	 * Long.parseLong(timeStamp)
	 * 
	 * @param timeStamp
	 *            1451750400
	 * @return 03
	 */
	public static int getDayByTimeStamp(long timeStamp) {
		String date = timeStamp2Date(timeStamp);
		String day = date.substring(8, 10);
		return Integer.parseInt(day);
	}

	/**
	 * Long.parseLong(timeStamp)
	 * 
	 * @param timeStamp
	 *            1451750400
	 * @return 00
	 */
	public static int getHourByTimeStamp(long timeStamp) {
		String date = timeStamp2Date(timeStamp);
		String hour = date.substring(11, 13);
		return Integer.parseInt(hour);
	}

	/**
	 * Long.parseLong(timeStamp)
	 * 
	 * @param timeStamp
	 *            1451750400
	 * @return 00
	 */
	public static int getMinuteByTimeStamp(long timeStamp) {
		String date = timeStamp2Date(timeStamp);
		String minute = date.substring(14, 16);
		return Integer.parseInt(minute);
	}

	/**
	 * Long.parseLong(timeStamp)
	 * 
	 * @param timeStamp
	 *            1451750400
	 * @return 00
	 */
	public static int getSecondByTimeStamp(long timeStamp) {
		String date = timeStamp2Date(timeStamp);
		String second = date.substring(17, 19);
		return Integer.parseInt(second);
	}

	/**
	 * @param timeStamp
	 *            1451750400
	 * @return 2016/01/03 00:00:00
	 */
	@SuppressLint("SimpleDateFormat")
	private static String timeStamp2Date(long timeStamp) {
		java.util.Date date = new java.util.Date(timeStamp * 1000);
		java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String dateStr = simpleDateFormat.format(date);
		return dateStr;
	}

	/****
	 * mm:ss
	 * 
	 * @return
	 */
	@SuppressLint("SimpleDateFormat")
	public static String getRefreshTime() {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		return dateFormat.format(new Date());
	}

	@SuppressLint("SimpleDateFormat") 
	public static String getReTime() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日    HH:mm:ss");
		Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
		String str = formatter.format(curDate);
		return str;
	}
}
